package kr.ac.kaist.idb.csnql.clause;

import java.io.Serializable;

/**
 * 
 * @brief FROM clause class
 * @author Minjee Park
 *
 */
public class SNQLFromItem implements Serializable
{
	
	/**
	 * @brief Serial version UID which is automatically generated
	 */
	private static final long serialVersionUID = -2376202056810074675L;

	/** @brief FROM type Boundary */
	public final static int BOUNDARY_TYPE = 1;
	
	/** @brief FROM type region*/
	public final static int REGION_TYPE = 2;
	/** @brief Type of this clause */
	private int from_type;
	
	/**
	 * @brief FROM string
	 */
	private String x;
	private String y;
	private int distance;
	private String region1;
	private String op;
	private String region2;	
	
	private String targetarea;
	
	  /**
     * @brief Instantiates a new SNQLFromItem with string
     *
     * 
     */
	
	public SNQLFromItem(){
		this.from_type = 0;
		this.x = new String("x");
		this.y = new String("Y");
		distance=0;
		region1 = new String("r1");
		op = new String("op");
		region2 = new String("r2");			
		targetarea = new String("error");
		
	}
	  /**
     * @brief Instantiates a new SNQLFromItem with string
     *
     * @param int type,String x,String y, int distance
     */
    
    public void setboundarySNQLFrom(int type,String x,String y, int distance)
    {
    	this.from_type = type;
    	this.x = x;
    	this.y=y;
    	this.distance=distance;
    	
    }
    
	/**
     * @brief Instantiates a new SNQLFromItem
     * @param int type, String s
     */
    public void setOneregionSNQLFrom(int type, String s)
    {  
    	this.from_type = type;
    	setRegion1(new String(s));
    	
    }

    /**
     * @brief Instantiates a new SNQLFromItem with string
     *
     * @param int type, String s1, String op,String s2
     */
    
    public void setTworegionSNQLFrom(int type, String s1, String op,String s2)
    {
    	this.from_type = type;
    	this.setRegion1(new String(s1));
    	this.setOp(new String(op));
    	this.setRegion2(new String(s2));
    }
    
	public String getRegion1() {
		return region1;
	}

	public void setRegion1(String region1) {
		this.region1 = region1;
	}

	public String getOp() {
		return op;
	}

	public void setOp(String op) {
		this.op = op;
	}

	public String getRegion2() {
		return region2;
	}

	public void setRegion2(String region2) {
		this.region2 = region2;
	}
	   
    public String toString()
    {
    	StringBuffer stringbuffer = new StringBuffer();
    
    
		switch(from_type)
		{
		case BOUNDARY_TYPE:
			stringbuffer.append("BOUNDARY(("+x+","+y+"),"+distance+")");
			break;
		case REGION_TYPE:
			if(op.compareTo(new String("op")) != 0){
	    		stringbuffer.append(region1+op+region2);
	    	}else{
	    		stringbuffer.append(region1);
	    	}
		default :
			break;
		}
		return stringbuffer.toString();
    }

	public int getFrom_type() {
		return from_type;
	}

	public void setFrom_type(int from_type) {
		this.from_type = from_type;
	}
	


	public String getX() {
		return x;
	}

	public void setX(String x) {
		this.x = x;
	}

	public String getY() {
		return y;
	}

	public void setY(String y) {
		this.y = y;
	}

	public void setDistance(int distance) {
		this.distance = distance;
	}

	public int getDistance() {
		return distance;
	}

	public String getTargetarea() {
		return targetarea;
	}
//QueryPlanner calculate and set the targetArea coordinate
	public void setTargetarea(String targetarea) {
		this.targetarea = targetarea;
	}
}
